﻿using System;
using Character;
using UnityEngine;
using Utility;

// Token: 0x02000140 RID: 320
public abstract class CharaShapeCustomBase
{
	// Token: 0x06000776 RID: 1910 RVA: 0x0002C9DC File Offset: 0x0002ABDC
	public CharaShapeCustomBase(Human human)
	{
		this.human = human;
		this.customHighlightMaterialPath = ((human.sex != SEX.FEMALE) ? CharaShapeCustomBase.customHighlightMaterialPath_M : CharaShapeCustomBase.customHighlightMaterialPath_F);
		this.customHighlightMaterialName = ((human.sex != SEX.FEMALE) ? CharaShapeCustomBase.customHighlightMaterialName_M : CharaShapeCustomBase.customHighlightMaterialName_F);
	}

	// Token: 0x170000D8 RID: 216
	// (get) Token: 0x06000777 RID: 1911 RVA: 0x0002CA38 File Offset: 0x0002AC38
	// (set) Token: 0x06000778 RID: 1912 RVA: 0x0002CA40 File Offset: 0x0002AC40
	public string customHighlightMaterialPath { get; protected set; }

	// Token: 0x170000D9 RID: 217
	// (get) Token: 0x06000779 RID: 1913 RVA: 0x0002CA4C File Offset: 0x0002AC4C
	// (set) Token: 0x0600077A RID: 1914 RVA: 0x0002CA54 File Offset: 0x0002AC54
	public string customHighlightMaterialName { get; protected set; }

	// Token: 0x170000DA RID: 218
	// (get) Token: 0x0600077B RID: 1915 RVA: 0x0002CA60 File Offset: 0x0002AC60
	public GameObject Obj
	{
		get
		{
			return this.obj;
		}
	}

	// Token: 0x170000DB RID: 219
	// (get) Token: 0x0600077C RID: 1916 RVA: 0x0002CA68 File Offset: 0x0002AC68
	public ShapeInfoBase Info
	{
		get
		{
			return this.info;
		}
	}

	// Token: 0x170000DC RID: 220
	// (get) Token: 0x0600077D RID: 1917 RVA: 0x0002CA70 File Offset: 0x0002AC70
	// (set) Token: 0x0600077E RID: 1918 RVA: 0x0002CA78 File Offset: 0x0002AC78
	public bool IsShapeChange { get; protected set; }

	// Token: 0x170000DD RID: 221
	// (get) Token: 0x0600077F RID: 1919 RVA: 0x0002CA84 File Offset: 0x0002AC84
	public Material SkinMaterial
	{
		get
		{
			return this.skinMaterial;
		}
	}

	// Token: 0x170000DE RID: 222
	// (get) Token: 0x06000780 RID: 1920 RVA: 0x0002CA8C File Offset: 0x0002AC8C
	public Renderer Rend_skin
	{
		get
		{
			return this.rend_skin;
		}
	}

	// Token: 0x170000DF RID: 223
	// (get) Token: 0x06000781 RID: 1921 RVA: 0x0002CA94 File Offset: 0x0002AC94
	public Material CustomHighlightMat_Skin
	{
		get
		{
			return this.customHighlightMat_Skin;
		}
	}

	// Token: 0x170000E0 RID: 224
	// (get) Token: 0x06000782 RID: 1922 RVA: 0x0002CA9C File Offset: 0x0002AC9C
	public Animator Anime
	{
		get
		{
			return this.anime;
		}
	}

	// Token: 0x06000783 RID: 1923 RVA: 0x0002CAA4 File Offset: 0x0002ACA4
	public void Update()
	{
		if (this.IsShapeChange)
		{
			this.ShapeApply();
		}
	}

	// Token: 0x06000784 RID: 1924
	public abstract void ShapeApply();

	// Token: 0x06000785 RID: 1925
	public abstract void SetShape(int category, float value);

	// Token: 0x06000786 RID: 1926
	public abstract float GetShape(int category);

	// Token: 0x06000787 RID: 1927 RVA: 0x0002CAB8 File Offset: 0x0002ACB8
	protected void Setup_MaterialAndTexture(Renderer rend_skin, string name_skinMaterial)
	{
		this.Setup_Material(rend_skin, name_skinMaterial);
		this.Setup_Texture();
	}

	// Token: 0x06000788 RID: 1928 RVA: 0x0002CAC8 File Offset: 0x0002ACC8
	protected void Setup_Material(Renderer rend_skin, string name_skinMaterial)
	{
		int num = -1;
		for (int i = 0; i < rend_skin.sharedMaterials.Length; i++)
		{
			if (rend_skin.sharedMaterials[i].name.ToLower().IndexOf(name_skinMaterial.ToLower()) == 0)
			{
				num = i;
				this.skinMaterial = new Material(rend_skin.sharedMaterials[i]);
				this.skinMaterial.name = name_skinMaterial + "_CustomMaterial";
				break;
			}
		}
		if (num != -1)
		{
			this.rend_skin = rend_skin;
			this.skinMaterialNo = num;
			MaterialUtility.SwapSharedMaterials(rend_skin, num, this.skinMaterial);
		}
	}

	// Token: 0x06000789 RID: 1929 RVA: 0x0002CB64 File Offset: 0x0002AD64
	private void Setup_Texture()
	{
		int width = this.skinMaterial.mainTexture.width;
		int height = this.skinMaterial.mainTexture.height;
		this.skinBaseTex = this.skinMaterial.mainTexture;
		this.skinTex = new RenderTexture(width, height, 0);
		this.skinTex.wrapMode = this.skinBaseTex.wrapMode;
		this.skinTex.useMipMap = true;
		Texture texture = this.skinMaterial.GetTexture("_BumpMap");
		width = texture.width;
		height = texture.height;
		this.normalTex = new RenderTexture(width, height, 0);
		this.normalTex.wrapMode = texture.wrapMode;
		this.normalTex.useMipMap = true;
	}

	// Token: 0x0600078A RID: 1930 RVA: 0x0002CC20 File Offset: 0x0002AE20
	protected void SetTattooOffsetAndTiling(Material mat, string propertyName, int baseW, int baseH, int texW, int texH, float offsetPx, float offsetPy)
	{
		float num = (float)baseW / (float)texW;
		float num2 = (float)baseH / (float)texH;
		float x = -(offsetPx / (float)baseW) * num;
		float y = -(((float)baseH - offsetPy - (float)texH) / (float)baseH) * num2;
		mat.SetTextureOffset(propertyName, new Vector2(x, y));
		mat.SetTextureScale(propertyName, new Vector2(num, num2));
	}

	// Token: 0x0600078B RID: 1931 RVA: 0x0002CC78 File Offset: 0x0002AE78
	public virtual void CreateCustomHighlightMaterial()
	{
		this.CreateCustomHighlightMaterial(ref this.customHighlightMat_Skin, this.rend_skin);
	}

	// Token: 0x0600078C RID: 1932 RVA: 0x0002CC8C File Offset: 0x0002AE8C
	public virtual void DeleteCustomHighlightMaterial()
	{
		this.DeleteCustomHighlightMaterial(ref this.customHighlightMat_Skin, this.rend_skin);
	}

	// Token: 0x0600078D RID: 1933 RVA: 0x0002CCA0 File Offset: 0x0002AEA0
	protected void CreateCustomHighlightMaterial(ref Material customHighlightMat, Renderer rend)
	{
		int num = -1;
		for (int i = 0; i < rend.sharedMaterials.Length; i++)
		{
			if (rend.sharedMaterials[i].name.IndexOf(this.customHighlightMaterialName) == 0)
			{
				num = i;
			}
		}
		if (num == -1)
		{
			if (customHighlightMat == null)
			{
				Material source = Resources.Load<Material>(this.customHighlightMaterialPath + this.customHighlightMaterialName);
				customHighlightMat = new Material(source);
			}
			MaterialUtility.AddSharedMaterials(rend, customHighlightMat);
		}
	}

	// Token: 0x0600078E RID: 1934 RVA: 0x0002CD24 File Offset: 0x0002AF24
	protected void DeleteCustomHighlightMaterial(ref Material customHighlightMat, Renderer rend)
	{
		if (customHighlightMat != null)
		{
			Material[] sharedMaterials = rend.sharedMaterials;
			int num = -1;
			for (int i = 0; i < sharedMaterials.Length; i++)
			{
				if (sharedMaterials[i].name.IndexOf(this.customHighlightMaterialName) == 0)
				{
					num = i;
				}
			}
			if (num != -1)
			{
				Material[] array = new Material[sharedMaterials.Length - 1];
				int num2 = 0;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (j != num)
					{
						array[num2] = sharedMaterials[j];
						num2++;
					}
				}
				rend.sharedMaterials = array;
			}
			UnityEngine.Object.Destroy(customHighlightMat);
			customHighlightMat = null;
		}
	}

	// Token: 0x0600078F RID: 1935 RVA: 0x0002CDCC File Offset: 0x0002AFCC
	public virtual void UpdateCustomHighlightMaterial()
	{
		if (this.customHighlightMat_Skin)
		{
			this.CreateCustomHighlightMaterial();
		}
	}

	// Token: 0x06000790 RID: 1936 RVA: 0x0002CDE4 File Offset: 0x0002AFE4
	public static string GetCustomHighlightMaterialPath(SEX sex)
	{
		return (sex != SEX.FEMALE) ? CharaShapeCustomBase.customHighlightMaterialPath_M : CharaShapeCustomBase.customHighlightMaterialPath_F;
	}

	// Token: 0x06000791 RID: 1937 RVA: 0x0002CDFC File Offset: 0x0002AFFC
	public static string GetCustomHighlightMaterialName(SEX sex)
	{
		return (sex != SEX.FEMALE) ? CharaShapeCustomBase.customHighlightMaterialName_M : CharaShapeCustomBase.customHighlightMaterialName_F;
	}

	// Token: 0x0400076C RID: 1900
	protected static readonly string customHighlightMaterialPath_F = "Custom Point F/Materials/";

	// Token: 0x0400076D RID: 1901
	public static readonly string customHighlightMaterialName_F = "cf_M_point";

	// Token: 0x0400076E RID: 1902
	protected static readonly string customHighlightMaterialPath_M = "Custom Point M/Materials/";

	// Token: 0x0400076F RID: 1903
	public static readonly string customHighlightMaterialName_M = "cm_M_point";

	// Token: 0x04000772 RID: 1906
	protected Human human;

	// Token: 0x04000773 RID: 1907
	protected GameObject obj;

	// Token: 0x04000774 RID: 1908
	protected ShapeInfoBase info;

	// Token: 0x04000776 RID: 1910
	protected Texture skinBaseTex;

	// Token: 0x04000777 RID: 1911
	protected Texture skinNormalTex;

	// Token: 0x04000778 RID: 1912
	protected RenderTexture skinTex;

	// Token: 0x04000779 RID: 1913
	protected RenderTexture normalTex;

	// Token: 0x0400077A RID: 1914
	protected Material skinMaterial;

	// Token: 0x0400077B RID: 1915
	protected Renderer rend_skin;

	// Token: 0x0400077C RID: 1916
	protected int skinMaterialNo;

	// Token: 0x0400077D RID: 1917
	protected Material customHighlightMat_Skin;

	// Token: 0x0400077E RID: 1918
	protected Animator anime;
}
